package com.hnkywl.sts.dao.organ;

import com.hnkywl.sts.entity.organ.Ysgj;
import net.ruixin.orm.hibernate.Page;
import net.ruixin.orm.hibernate.SimpleHibernateTemplate;
import org.hibernate.Query;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.hibernate.tool.hbm2x.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-3-29
 * Time: 下午3:36
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class YsgjDao extends SimpleHibernateTemplate<Ysgj,Long> {
    /**
     * 查询运输工具列表
     * @param wlsId      物流商ID
     * @param pageNo
     * @param pageSize
     * @return
     */
    public Page<Ysgj> findYsgjList(Long wlsId,int pageNo, int pageSize){
        Page<Ysgj> page = new Page<Ysgj>();
        page.setAutoCount(true);
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        page.setOrder("desc");
        page.setOrderBy("lastUpdated");
        if(wlsId!=null){
            return this.findByCriteria(page,new Criterion[]{Restrictions.eq("wls.id", wlsId)});
        }else
            return this.findAll(page);
    }

    public boolean checkQc(Long id,String ysgjsbm) {
        if (id == null){
            //新增校验
            String hql = "from Ysgj where ysgjsbm = ?";
            return existsQuery(hql,ysgjsbm);
        } else {
            //修改校验
            String hql = "from Ysgj where id<>? and ysgjsbm = ?";
            return existsQuery(hql,id,ysgjsbm);
        }
    }
}
